package com.zhida.chatservice.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.zhida.chatservice.service.IAnnouncementService;
import com.zhida.common.entity.Announcement;
import com.zhida.common.entity.Result;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ling
 * @since 2024-07-23
 */
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {

    @Resource
    IAnnouncementService iAnnouncementService;

    //  发布公告
    @RequestMapping("/create")
    public Result<?> createAnnouncement(@RequestBody Announcement announcement) {
        return iAnnouncementService.createAnnouncement(announcement);
    }
    //  删除公告
    @GetMapping("/delete/{id}")
    public Result<?> deleteAnnouncement(@PathVariable Integer id) {
        return iAnnouncementService.deleteAnnouncement(id);
    }
    //  查询公告
    @GetMapping("/getById/{id}")
    public Result<?> getAnnouncementById(@PathVariable Integer id) throws JsonProcessingException {
        return iAnnouncementService.getAnnouncementById(id);
    }
    //  查询最近的一条公告
     @RequestMapping("/getLatest/{group_id}")
     public Result<?> getLatestAnnouncement(@PathVariable Integer group_id) {
          return iAnnouncementService.getLatestAnnouncement(group_id);
     }
    //  更新公告
     @RequestMapping("/update")
     public Result<?> updateAnnouncement(@RequestBody Announcement announcement) {
         return iAnnouncementService.updateAnnouncement(announcement);
     }
    //  推送公告
     @GetMapping("/push/{id}")
     public Result<?> pushAnnouncement(@PathVariable Integer id) {
         return iAnnouncementService.pushAnnouncement(id);
     }
}
